Delphi Suggestions - Compiler
Chrome? Implement all the features of Chrome http://www.chromesville.com/language/ or buy it and integrate into Delphi. Generics MyList := TGenericList.Create ; Widths := TGenericList.Create; Var Initialization var I: Integer = 0; begin instead of var I: Integer; begin I := 0 Implementation status: this syntax is already existing, but the variabele is only initialised on startup. So this would require additional syntax. Variable Constraints The ability to define constraints on a variable, if these are violated, an exception is raised. var I:Integer; S:String; ٍsI:String; constraint I > 15; constraint I mod 5=3; constraint length(S)<50; constraint length(S)+I > 8; constraint (sI = IntToStr(I)) or (sI='''); (probably with a more elegant syntax... and working like assertions, only in the $C+ state, right?) Note that this is different from assertions: An assertion only checks a variable at a certain point in the program, a constraint would check it every time it is accessed. Example: var i: integer; constraint i > 15; begin i := 16; Assert(i > 16); // checks now -> OK i := i - 1; // the constraint is violated, but the assertion above // cannot catch it. Contstraints are somewhat similar to subrange types with range checking on but allow for more complex conditions. Automatic Create/Free Automatic call of Create/Free for objects created in a function/method by using a specific language keyword : var S: TStringList; begin try ... S := TStringList.Create; S.Add('hi !'); ... finally S.Free; end; end; Are the calls to Create() and Destroy() _really_ useful ? We should be able with the usage of a keyword or a special character to reduce this to : var S: TStringList; auto; begin S.Add('hi !'); end; Obviously, the usage of this syntax would embed try/finally statements in order to free the object even if an exception is thrown inside the function). If the constructor takes parameters, they could be provided in the VAR section : procedure SaveFile(const AFilePath: string); var S: TFileStream(AFilePath); auto; begin ... end; THobo = class(TUsers) FStrings: TStringList; auto; public FUsers: TStringList; auto; end; _I would like a more delphi-like syntax:_ var S: auto TStringList; begin S.Add('hi !'); end; Multithreading procedure DoSomethingInAThread (AString:String;AnInteger:Integer); async; procedure DoSomethingElseInAThread (AString:String;AnInteger:Integer); async group 3; procedure DoSomethingElse2InAThread (AString:String;AnInteger:Integer); async group 3; This would execute the procedure in a separate thread.... With all these multi-core CPUs getting to the market, this is getting more and more a priority. global list of threads where threads are registered upon construction and unregistered on destruction. Than this list would have a method GetCurrentThread: TThread, so one can retrieve the thread that is currently running Waiting for Threads to finish WaitForThreads; WaitForThreads(3); Another Idea Have a look at Cilk, Cilk is an algorithmic multithreaded language. The philosophy behind Cilk is that a programmer should concentrate on structuring the program to expose parallelism and exploit locality, leaving Cilk's runtime system with the responsibility of scheduling the computation to run efficiently on a given platform. Thus, the Cilk runtime system takes care of details like load balancing, paging, and communication protocols. To give you an idea of how simple it is to write parallel programs using Cilk, here is a sample of what a could be done similarly in Delphi: an implementation of the familiar recursive Fibonacci program in which the recursive calls are executed in parallel: function fib (n:integer): integer; cilk; var x,y:integer; begin if (n < 2) then result:=n else begin x = spawn fib (n-1); y = spawn fib (n-2); sync; result:=x+y; end; end; AsyncCalls have a look at AsyncCalls, It allows easy multithreading in Delphi.... With AsyncCalls you can execute multiple functions at the same time and synchronize them at every point in the function or method that started them. This allows you to execute time consuming code whos result is needed at a later time in a different thread. While the asynchronous function is executed the caller function can do other tasks. The AsyncCalls unit offers a variety of function prototypes to call asynchronous functions. There are functions that can call asynchron functions with one single parameter of the type: TObject, Integer, AnsiString, WideString, IInterface, Extended and Variant. Another function allows you to transfer a user defined value type (record) to the asynchron function where it can be modify. And there are functions that can call asynchron functions with a variable number of arguments. The arguments are specified in an const array of const and are automatically mapped to normal function arguments. Case allow case to handle more than ordinals, and handle more than lists. case s of 'abc': DoSomething; 'xyz': begin DoLots; DoLots; DoLots; end; else DoSomethingElse; end; case Sender of Button1: DoSomething; BitBtn13: DoSomethingElse; CheckBox1: case ListBox1.Items.Count of <10: DoSomething; 10..12: DoSomethingElse; >12,<25: DoThis; >=25: DoThat; end; end; Implementatation notes: The trouble with this is that case then would be a runtime construct, which it isn't now. This then could all kinds of unpredictable results. (e.g. what if more than one condition would be true). This would probably cause each case statement to be forcedly evaluated, causing great slowdown. Map function map(p:procedure; a:array); example: var a:array of Integer; s:Integer; procedure addsum(i:integer); begin s:=s+i; end; s:=0; map(addsum,a); writeln(s); (This dirty version of enclosures has been doable for ages... or am I missing something?) Split,Join, Push and Pop for Arrays; (having array helpers instead would make implementing this very easy) Try Why do we have to do something as ugly as: try try // yada except // yada end; finally // yada end; rather than the elegant try // yada except // yada finally // yada end; Regular Expressions var a:array of string; s:string; readln(s); for a in RegExpMatch(s,'/(.*)/') do begin writeln a1; end; RegExpReplace(s,'/(a-z)/',inttostr(ord(RegExpMatch(1))); Language Constructs * Multiline String Constants * Anonymous Arrays * Anonymous functions/procedures (already available, right? although the syntax is somehow odd) Pascal * allow the end before an else statement to have a semicolon; :The lack of a semicolon tells the compiler that the following "else" belongs to the current "if" and not to a container "if" statement. If the semicolon was allowed the compiler would have to do more work (read less efficient) to determine which "if" statement the "else" belongs to. Eddie 18:16, 29 October 2006 (UTC) * a better syntax for the with statement, see qc for various suggestions. Class Helpers Even though they started as a hack, having multiple class helpers for a class would be nice to have, also imagine class helpers that could be registered as components, they would only apply when put on a form (as a non visual component). Allow to enable or disable a specific class helper. TNiceDBGrid=class helper for TDBGrid; TColoredDBGrid=class helper for TDBGrid; DBGrid1.ClassHelperTColoredDBGrid.Enabled:=false; Interface Helpers Same idea, why can't helpers be also for interfaces? Arrays Allow Array Keys to be other than integers. This includes an optimzed string-based hash. as well as the ability to use any data type as an index .... var Captions: ArrayTComponent of String; C:TComponent; begin for C in Components do CaptionsC:=C.Caption; //Do Some Stuff result:=join(' ',Captions); end; See the note about array helpers, and the new syntax for records, should help here? Distributed this should run in a cluster (MPI/PVM/????) as in procedure DoSomethingInACluster (AString:String;AnInteger:Integer); async; distributed; or even: var a:Array of String; function MapSomething(DocID:Array of Integer):Array of String; function ReduceSomething(Maps:Array of String):Array of String; a:=ReduceSomething(MapSomething(1..1000000)); Inline Functions and Procedures Have the possibility to perform "inline of functions" (as C/C++/Perl). Status: Already implemented in D2005+ and FPC 2.0+. Category:Delphi Suggestions